package annotations;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
public class AnnotationTest3 {
    public static void main(String[] args) throws Exception {
        // 1. 解析类上的注解
        Class<Demo> demoClass = Demo.class;
        parseAnnotation(demoClass.getAnnotation(MyTest4.class), "类");

        // 2. 解析方法上的注解
        Method test1Method = demoClass.getMethod("test1");
        parseAnnotation(test1Method.getAnnotation(MyTest4.class), "方法");
    }

    private static void parseAnnotation(MyTest4 annotation, String target) {
        if (annotation != null) {
            System.out.println("=== " + target + "上的MyTest4注解信息 ===");
            System.out.println("value值: " + annotation.value());
            System.out.println("aaa值: " + annotation.aaa());
            System.out.println("bbb数组值: ");
            for (String item : annotation.bbb()) {
                System.out.println("  " + item);
            }
            System.out.println("========================");
        } else {
            System.out.println(target + "上没有MyTest4注解");
        }
    }
}